/*
 * Copyright (C) 2012 haru Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.harusource.test;

import com.harusource.di.core.activity.HaruExpandableListActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

/**
 * 
 * @author Hiroki Oizumi
 *
 */
public class SampleMainActivity extends HaruExpandableListActivity {
    /**
     * Parent data of ExpandableListView
     */
    private static final String[] GROUPS = {
            "Basic", "Inject Instance", "Handle Event"
    };

    /**
     * Child data of ExpandableListView<br>
     * <br>
     * CHILDREN[m][n][0] : text shown in child text area as main text<br>
     * CHILDREN[m][n][1] : text shown in child text area as sub text<br>
     * CHILDREN[m][n][2] : additional information for a process after selecting child
     */
    private static final String[][][] CHILDREN = {
            {
                    {
                            "Activity", "Using HaruActivity",
                            "com.harusource.test.SampleHaruActivity"
                    }, {
                            "ListActivity", "Using HaruListActivity", "com.harusource.test.SampleHaruListActivity"
                    }, {
                            "ExpandableActivity", "Using HaruExpandableActivity"
                    }, {
                            "TabActivity", "Using HaruTabActivity"
                    }
            }, {
                    {
                            "Child21", "Text21"
                    }, {
                            "Child22", "Text22"
                    }
            }, {
                    {
                            "Child31", "Text31"
                    }, {
                            "Child32", "Text32"
                    }, {
                            "Child33", "Text33"
                    }
            },
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(getSimpleExpandableListAdapter(GROUPS, CHILDREN));
    }

    /**
     * When user click a child row, process starting a sample activity.
     */
    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
            int childPosition, long id) {
        try {
            //get a Class from selection
            Class<?> activity = Class.forName(CHILDREN[groupPosition][childPosition][2]);
            
            // start a sample
            startActivity(new Intent(this.getApplicationContext(), activity));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
